﻿using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Traceability.Commont.Infrastructures.Interfaces;

namespace Traceability.Commont.Domains
{
    public class Entitys : IDomainEvent
    {
        /// <summary>
        /// 存储领域模型下所有的领域事件
        /// </summary>
        List<INotification> DoaminEvents=new List<INotification>();
        /// <summary>
        /// 注册领域事件
        /// </summary>
        /// <param name="notification"></param>
        public void AddDomainEvent(INotification notification)
        {
            DoaminEvents.Add(notification);
        }
        /// <summary>
        /// 如果领域事件不存在，则注册事件
        /// </summary>
        /// <param name="notification"></param>
        public void AddDomianEventIfAbsent(INotification notification)
        {
            if (DoaminEvents.Contains(notification))
            {
                DoaminEvents.Add(notification);
            }
        }
        /// <summary>
        /// 清除注册的领域事件
        /// </summary>
        public void ClearDomainEvents()
        {
            DoaminEvents.Clear();
        }
        /// <summary>
        /// 获取注册得领域事件
        /// </summary>
        /// <returns></returns>
        public IEnumerable<INotification> GetDoaminEvents()
        {
            return DoaminEvents;
        }
    }
}
